package com.boot.security;

import cn.hutool.json.JSONUtil;
import com.boot.api.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
@Slf4j
public class IlAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        log.warn("===============这个是什么" + ApiResult.unAuthentication().getMessage());
        response.setContentType("text/json;charset=UTF8");
        response.getWriter().write(JSONUtil.toJsonStr(ApiResult.unAuthentication()));
    }
}
